
const user = {
  state: {
    userInfo: null,
    userList: []
  },

  mutations: {
    SET_USER: (state, userInfo) => {
      state.userInfo = userInfo
    },
    SET_USERLIST: (state, userList) => {
      state.userList = userList
    },
  },

  actions: {
    AddUserList({ commit }, userList) {
      if (!userList || userList.length < 1) {
        commit('SET_USERLIST', [])
        return
      }
      
      const newUserList = userList.filter(item => item.loginStatus === 1 && item.cookie)
      commit('SET_USERLIST', newUserList)
    },

    SetUser({ commit }, userInfo) {
      commit('SET_USER', userInfo)
    },
  }
}

export default user
